// pages/readWorks/searchOclock/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeIndex: -1,
    list: [],
    nj: '',
    bj: '',
    publishid: '',
    name: '',
    prompt: {
      hidden: 0,
      icon: '../../../assets/images/iconfont-order-default.png',
      title: '暂无数据',
      text: '没有任何打卡记录',
      gurl: '../../pages/home/home',
      gtype: "switchTab"
    },
    navList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      publishid: options.publishid
    })
    this.firstWorkPageFinish()
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  // 首次查询完成情况
  firstWorkPageFinish () {
    const that = this
    const publishid = this.data.publishid
    wx.showLoading({
      title: '加载中...',
    })
    app.wxget({
      url: 'issuedWorks/workPageFinishNew.html',
      data: {
        publishid: publishid
      },
      success: function (res) {
        wx.hideLoading()
        if (res.data.result) {
          console.log(res.data.result)
          var list = res.data.list
          that.setData({
            list: list
          })
          var navList = res.data.navList
          if (navList.length > 0) {
            let nav = navList[0]
            that.setData({
              navList: navList
            })
            that.setData({
              activeIndex: 0,
              nj: nav.nj
            })
            if (nav.bj) {
              that.setData({
                bj: nav.bj
              })
            }
          }
        }
      }
    })
  },

  nameinput (e) {
    this.setData({
      name: e.detail.value
    })
  },

  // 切换班级
  onTapTag (e) {
    const index = e.currentTarget.dataset.index
    let navList = this.data.navList
    let nav = navList[index]
    this.setData({
      activeIndex: index,
      nj: nav.nj
    })
    if (nav.bj) {
      this.setData({
        bj: nav.bj
      })
    }
    this.workPageFinish()
  },
  
    // 根据条件查询完成情况
  workPageFinish () {
      const that = this
      const publishid = this.data.publishid
      wx.showLoading({
        title: '加载中...',
      })
      app.wxget({
        url: 'issuedWorks/workPageFinishByTj.html',
        data: {
          publishid: publishid,
          name: that.data.name,
          nj: that.data.nj,
          bj: that.data.bj
        },
        success: function (res) {
          console.log(res)
          wx.hideLoading()
          that.setData({
            list: res.data
          })
        }
      })
  },

  //查看打开详情
  toOclockDetail(e) {
    const publishid = e.currentTarget.dataset.publishid
    const usid = e.currentTarget.dataset.usid
    const percent = e.currentTarget.dataset.percent
    wx.navigateTo({
      url: '../oclockDetail/index?publishid=' + publishid + '&usid=' + usid + '&percent=' + percent
    })
  }

})